<?php

namespace XXXX\PlatformBundle\Repository;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;

/**
 * UserNotificationRepository
 *
 * @author Ryszard Ratajczak <rrtajczak@xxxx.com.pl>
 */
class UserNotificationRepository extends EntityRepository
{
    /**
     * UserNotificationRepository
     *
     * @param integer $courseId  - id of course
     * @param integer $studentId - id of user
     *
     * @return ArrayCollection
     */
    public function getUserCourseNotifications($courseId, $studentId)
    {
        return $this->createQueryBuilder('un')
            ->select('un')
            ->join('un.notification', 'n')
            ->join('n.course', 'c')
            ->join('un.user', 'u')
            ->where('c.id = :courseId')
            ->andWhere('u.id = :userId')
            ->andWhere('un.hidden = :hidden')
            ->setParameter('courseId', $courseId)
            ->setParameter('userId', $studentId)
            ->setParameter('hidden', false)
            ->getQuery()
            ->getResult();
    }
}
